package com.thunder.reader.transaction;

import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * Encapsulation of all stuff needed to know by a Transaction.
 * Currently only uri, which might be extended in future.
 *
 */
public class TransactionData implements Parcelable {
    private Uri mUri;
    private int mType;
    
    public TransactionData(Uri uri, int type) {
        mUri = uri;
        mType = type;
    }
    
    public Uri getUri() {
        return mUri;
    }
    
    public int getType() {
        return mType;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((mUri == null) ? 0 : mUri.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        TransactionData other = (TransactionData) obj;
        if (mUri == null) {
            if (other.mUri != null) {
                return false;
            }
        } else if (!mUri.equals(other.mUri)) {
            return false;
        }
        return true;
    }

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(mUri, 0);
        dest.writeInt(mType);
    }
    
    public static final Parcelable.Creator<TransactionData> CREATOR = new Parcelable.Creator<TransactionData>() {
        public TransactionData createFromParcel(Parcel in) {
            return new TransactionData(in);
        }

        public TransactionData[] newArray(int size) {
            return new TransactionData[size];
        }
    };

    private TransactionData(Parcel in) {
        mType = in.readInt();
        mUri = in.readParcelable(getClass().getClassLoader());
    }
}